package tech.xs.sys.domain.bo.user;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;
import tech.xs.common.framework.domain.constant.DatePattern;
import tech.xs.common.sys.domain.enums.SysAccountStatusEnum;
import tech.xs.common.domain.enums.SexEnum;
import tech.xs.common.framework.domain.exception.InvalidParameterException;
import tech.xs.common.util.ParameterVerificationUtil;
import tech.xs.sys.domain.entity.SysUser;

import javax.validation.constraints.NotBlank;
import java.time.LocalDate;

/**
 * @author 沈家文
 * @since 2023/6/21$ 15:59$
 */
@Getter
@Setter
@ToString
public class EditUserBo {

    protected Long id;
    @NotBlank
    @Length(min = 1, max = 32)
    private String userName;

    private String nickName;

    private String phone;

    private String email;

    private String realName;

    private String idNumber;

    private SexEnum sex;

    private SysAccountStatusEnum accountStatus;

    @JsonFormat(pattern = DatePattern.NORM_DATE_PATTERN)
    private LocalDate birthDate;

    private String introduction;

    public void checkParameter() {
        SysUser.checkUserName(userName, "userName");
        if (StrUtil.isNotBlank(phone) && !ParameterVerificationUtil.verifyPhone(phone)) {
            throw new InvalidParameterException("phone", "您输入的手机号不符合规范,请检查");
        }
        if (StrUtil.isNotBlank(idNumber) && !ParameterVerificationUtil.verifyIdNumber(idNumber)) {
            throw new InvalidParameterException("idNumber", "您输入的身份证号不符合规范,请检查");
        }
    }

}
